//
//  ShufflingFigureHelper.m
//  HomeDecoration
//
//  Created by xalo on 16/2/29.
//  Copyright © 2016年 美家项目组. All rights reserved.
//

#import "ShufflingFigureHelper.h"
#import <AFNetworking/AFNetworking.h>

@interface ShufflingFigureHelper ()

@property (nonatomic,strong) NSMutableArray *imageArray;


@end





@implementation ShufflingFigureHelper


+(ShufflingFigureHelper *)sharedManager
{
    static ShufflingFigureHelper *hendle = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        hendle = [[ShufflingFigureHelper alloc] init];
        
    });
    
    return hendle;

}


-(void)fetchImageWithUrl:(NSString *)url block:(BLOCK)block
{
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        
        [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
            
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSArray *array = [NSArray array];
            
            array = (NSArray *)responseObject;            
            
            for (NSDictionary *dic in array) {
                
                NSString *str = dic[@"imageUrl"];
                
                [self.imageArray addObject:str];
                
               
            }
           
            dispatch_async(dispatch_get_main_queue(), ^{
                
                block();
                
            });
            
             NSLog(@"%@",self.imageArray);
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            NSLog(@"%@",error);
            
        }];
    });

}


-(NSMutableArray *)imageArray
{
    if (!_imageArray) {
        
        _imageArray = [NSMutableArray array];
    }

    return _imageArray;
    
}

-(NSInteger)countOfImageArray
{
    return self.imageArray.count;
}

-(NSMutableArray *)returnImageArray
{
    return self.imageArray;
    
}




@end
